package com.atguigu.yygh.cmn.controller;

import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.hosp.common.result.Result;
import com.atguigu.yygh.hosp.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @version 1.0
 * @Author: 许啸林
 * @Date: 2021/7/7 15:32
 * 数据字典控制类
 */
@Api("数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict/")
@CrossOrigin
public class DictController {
    @Resource
    private DictService dictService;

    @ApiOperation("查询当前字典的子节点")
    @GetMapping("findDictItem/{id}")
    public Result findDictItem(@PathVariable Long id) {
        List<Dict> dictItems = dictService.getDictItem(id);
        return Result.ok(dictItems);
    }

    @ApiOperation("导出数据字典")
    @GetMapping("exportDict")
    public void exportDict(HttpServletResponse response) throws IOException {
        dictService.exprotData(response);
    }

    @ApiOperation("导入数据字典")
    @PostMapping("importDict")
    public Result importDict(MultipartFile file) {
        dictService.importDict(file);
        return Result.ok();
    }
}
